package com.alingrad.android.froyoengine.input;

import javax.microedition.khronos.opengles.GL10;

import android.view.MotionEvent;

import com.alingrad.android.froyoengine.tree.TreeNode;

public class TouchState extends TreeNode {
	public static final int ACTION_UP = MotionEvent.ACTION_UP;
	public static final int ACTION_DOWN = MotionEvent.ACTION_DOWN;
	public static final int ACTION_MOVE = MotionEvent.ACTION_MOVE;
	public static final int ACTION_CANCEL = MotionEvent.ACTION_CANCEL;
	
	public float mX;
	public float mY;
	public int mAction;
	public int mPointerId;
	private int mLastImportantAction;
	public boolean mActive;  
	
	public TouchState() {
		super();
		mLastImportantAction = -1;
		mActive = false;
	}

	public void set(float x, float y, int action) {
		mX = x;
		mY = y;
		if (action == ACTION_DOWN) {
			mAction = action;
			mLastImportantAction = action;
			mActive = true;
		} else if (action == ACTION_MOVE) {
			if (mLastImportantAction == -1) {
				mAction = action;
				mActive = true;
			}
		} else if (action == ACTION_UP) {
			if (mLastImportantAction == -1) {
				mAction = action;
				mActive = true;
			}
			else
				mActive = false;
		} else if (action == ACTION_CANCEL) {
			mAction = action;
			mActive = false;
		}
	}
	
	@Override
	public void load(GL10 gl) {
	}

	@Override
	public void update(long delta) {
		mLastImportantAction = -1;
		mActive = false;
	}

	public boolean isActive() {
		return mActive;
	}
	
	@Override
	public boolean isAlive() {
		return true;
	}
}
